using IQIGame.Onigao.Game;
using System;
using System.Text;

namespace IQIGame.Onigao.GamePlay
{
    /// <summary>
    /// 类名 : API - UI常量
    /// 作者 : Canyon / 龚阳辉
    /// 日期 : 2024-05-13 17:02
    /// 功能 : 
    /// </summary>
    public static class APIUIConst
    {
        /// <summary>
        /// 浮动窗体单条信息位置变化的更新间隔时间
        /// </summary>
        /// <returns>秒</returns>
        public const float IntervalUpFloatNotice = 0.8f;


        /// <summary>
        /// 浮动窗体单条信息位置变化的Y值
        /// </summary>
        /// <returns>px</returns>
        public const float AddYUpFLoatNotice = 5f;

        public const float IntervalShowFloatNoticeItem = 0.25f;
        public const float DeltaHideFloatNoticeItem = 1.5f;
        public const float IntervalHideFloatNoticeItem = 0.25f;
        public const float MaxShowFloatNoticeItem = 6;

        private static readonly int[] petMoneyAssets = { TableCenter.global.PetUnlockAttributeSlotCost[0], TableCenter.global.PetExpItemCid, };

        /// <summary>
        /// xxx不足
        /// </summary>
        public const int NoticeCid_ItemNotEnough = 20010;
        /// <summary>
        /// 请先点击升一级或Max
        /// </summary>
        public const int NoticeCid_UpPreNeed = 11000;
        /// <summary>
        /// 未接入SDK
        /// </summary>
        public const int NoticeCid_NoSDK = 11;
        /// <summary>
        /// 未接入SDK
        /// </summary>
        public const int NoticeCid_GetItems = 6;
        /// <summary>
        /// 传送点未激活
        /// </summary>
        public const int NoticeCid_Teleport = 500001;
        /// <summary>
        /// 传送点未激活
        /// </summary>
        public const int NoticeCid_CheckPointNotActive = 500013;
        /// <summary>
        /// 传送点未激活
        /// </summary>
        public const int NoticeCid_SameRegionTrace = 500015;
        /// <summary>
        /// 传送点未激活
        /// </summary>
        public const int NoticeCid_DifferentRegionTrace = 500016;

        /// <summary>
        /// 英雄默认的最大星数
        /// </summary>
        public const int HeroDefautMaxStar = 5;
        /// <summary>
        /// 二维数组的奖励与奖励之前的间距(heroCid,num)
        /// </summary>
        public const int RewardDefaultSpacing = 2;

        /// <summary>
        /// 二维数组的消耗与消耗之前的间距(heroCid,num)
        /// </summary>
        public const int CostDefaultSpacing = 2;

        public const int MailMaxCountLimit = 50;
        public const char MailCotentSplitChar = ';';

        /// <summary>
        /// 浮动窗体控制器的数据限定
        /// </summary>
        /// <returns>池总数,可显示总数</returns>
        static public (int, int) GetFLoatNoticeLimit()
        {
            int lmtAllCount = 20; // 限定池的总数
            int cntMaxShow = 5; // 限定显示总数
            return (lmtAllCount, cntMaxShow);
        }

        /// <summary>
        /// 界面资产 - ItemCids
        /// </summary>
        static public int[] GetItemCids4MoneyAsset(string uiName)
        {
            switch (uiName)
            {
                case nameof(UIWarehouse):
                    return new int[] { ItemConst.ItemCid_Gold, ItemConst.ItemCid_Diamond };
                case nameof(UIPetWarehouse):
                    return petMoneyAssets;
            }
            return null;
        }

        public static string GetMaxLabel()
        {
            return "Max";
        }

        static public string GetItemUseTipTitle()
        {
            return "使用道具";
        }

        static public string GetLvStr(object level)
        {
            return string.Format("Lv.{0}", level);
        }

        static public string GetLvLocalStr(int level)
        {
            return $"等级{level}";
        }

        static public string GetGreaterAddStr(int level)
        {
            if (level > 1)
                return $"+{level - 1}";
            return "";
        }

        public static int GetSubmitFailReason(UISubmitItem.SubmitFailReason reason)
        {
            switch (reason)
            {
                case UISubmitItem.SubmitFailReason.WrongCombination:
                    return 500010;
                case UISubmitItem.SubmitFailReason.NotEnough:
                default:
                    return 500011;
            }
        }

        public static string GetBuffTimeDescription()
        {
            //后续根据具体剩余时间/剩余堆叠/剩余生效次数来显示具体文本
            return "剩余时间:";
        }

        public static string SecondsToHMS(long seconds)
        {
            var secondsInt = (int)seconds;
            if (seconds <= 0)
            {
                return "-";
            }
            var hour = secondsInt / 3600;
            var minute = secondsInt % 3600 / 60;
            var second = secondsInt % 60;
            var sb = new StringBuilder();
            if (hour > 0)
            {
                sb.Append(hour);
                sb.Append("时");
            }

            if (minute > 0)
            {
                sb.Append(minute);
                sb.Append("分");
            }

            if (second > 0)
            {
                sb.Append(second);
                sb.Append("秒");
            }

            return sb.ToString();
        }

        /// <summary>
        /// 毫秒转x天x小时
        /// </summary>
        /// <param name="millisSeconds"></param>
        /// <returns></returns>
        public static string MillisSecondsToDH(long millisSeconds)
        {
            return SecondsToDH(millisSeconds / 1000);
        }
        /// <summary>
        /// 秒转x天x小时
        /// </summary>
        /// <param name="seconds"></param>
        /// <returns></returns>
        public static string SecondsToDH(long seconds)
        {
            var secondsInt = (int)seconds;
            if (seconds <= 0)
            {
                return string.Empty;
            }
            var nAllHour = secondsInt / 3600;
            var nDay = nAllHour / 24;
            var nHour = nAllHour % 24;
            return string.Format("{0}天{1}小时", nDay, nHour);
        }


        static public string GetDayHoursOrHourMinuteSeconds(int remainingSeconds)
        {
            if (remainingSeconds <= 0)
            {
                return string.Empty;
            }

            int days = remainingSeconds / DateTimeUtil.SecondsPerDay;
            if (days > 0)
            {
                int hours = (remainingSeconds % DateTimeUtil.SecondsPerDay) / DateTimeUtil.SecondsPerHour;
                return string.Format("{0}天{1}小时", days, hours);
            }

            return GetHourMinuteSeconds(remainingSeconds);
        }

        static private string GetHourMinuteSeconds(int remainingSeconds, string timeFormat = "{0:00}:{1:00}:{2:00}")
        {
            int hours = remainingSeconds / DateTimeUtil.SecondsPerHour;
            int minutes = (remainingSeconds % DateTimeUtil.SecondsPerHour) / DateTimeUtil.SecondsPerMinute;
            int seconds = (remainingSeconds % DateTimeUtil.SecondsPerMinute);
            return string.Format(timeFormat, hours, minutes, seconds);
        }

        /// <summary>
        /// 取得数值的字符串
        /// </summary>
        static public string GetNumStr(int num)
        {
            return num.ToString();
        }

        /// <summary>
        /// 简单长度(简单实现中文字符为2个字符的逻辑)
        /// </summary>
        static public int GetStrLenLimitCn(string str, bool isLmtCn2 = true)
        {
            if (string.IsNullOrEmpty(str))
                return 0;
            if (isLmtCn2)
            {
                Char c127 = Convert.ToChar(127);
                int i = 0;//字节数
                foreach (char c in str)
                {
                    if (c > c127)
                        i += 2;
                    else
                        i++;
                }
                return i;
            }
            return str.Length;
        }

        static public string GetOrderName(int index)
        {
            return index == 0 ? "降序" : "升序";
        }
    }
}
